package com.ebt.m.customer.util;

import android.text.TextUtils;
import android.widget.Toast;

import com.ebt.m.AppContext;
import com.ebt.m.BuildConfig;
import com.ebt.m.R;
import com.ebt.m.account.json.AccountResponse;
import com.ebt.m.account.json.ValidateCodeCheckResponse;
import com.ebt.m.account.json.ValidateCodeSendResponse;
import com.ebt.m.data.bean.UserInfo;
import com.ebt.m.commons.model.data.BaseDataResult;

/**
 * Created by Rick.Wang on 2016/12/17.
 */

public class ToastUtil {

    public static void showToast(String message){
        Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_SHORT).show();
    }

    public static void showToast(boolean b, String message) {
        if (b) {
            Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_SHORT).show();
        }
    }

    public static void showToastD(String message) {
        if (BuildConfig.ISDEBUG) {
            Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_SHORT).show();
        }
    }

    public static void showToastD(boolean b, String message) {
        if (BuildConfig.ISDEBUG && b) {
            Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_SHORT).show();
        }
    }

    public static void showToastL(String message){
        Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_LONG).show();
    }

    public static void showToastL(boolean b, String message) {
        if (b) {
            Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_LONG).show();
        }
    }

    public static void showToastDL(String message) {
        if (BuildConfig.ISDEBUG) {
            Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_LONG).show();
        }
    }

    public static void showToastDL(boolean b, String message) {
        if (BuildConfig.ISDEBUG && b) {
            Toast.makeText(AppContext.getInstance(), message, Toast.LENGTH_LONG).show();
        }
    }

    //验证码提示
    public static void showSendVCodeErrorMessage(BaseDataResult<ValidateCodeSendResponse> responseJson){
        if(responseJson != null && responseJson.getError() != null
                && !TextUtils.isEmpty(responseJson.getError().message)){
            ToastUtil.showToast(responseJson.getError().message);
        }else{
            ToastUtil.showToast(AppContext.getInstance().getString(R.string.get_vcode_failed));
        }
    }

    //快捷登录，验证码失败
    public static String getSendVCodeErrorMessage(BaseDataResult<ValidateCodeSendResponse> responseJson){
        String ret;
        if(responseJson != null && responseJson.getError() != null
                && !TextUtils.isEmpty(responseJson.getError().message)){
            ret = responseJson.getError().message;
        }else{
            ret = AppContext.getInstance().getString(R.string.get_vcode_failed);
        }
        return ret;
    }

    //获取用户绑定手机号
    public static void showGetUserInfoFail(BaseDataResult<UserInfo> responseJson){
        if(responseJson != null && responseJson.getError() != null
                && !TextUtils.isEmpty(responseJson.getError().message)){
            ToastUtil.showToast(responseJson.getError().message);
        }else{
            ToastUtil.showToast(AppContext.getInstance().getString(R.string.get_user_bind_info_failed));
        }
    }

    //快捷登录，验证码成功
    public static String getSendVCodeSuccessfullyMessage(){
        return AppContext.getInstance().getString(R.string.send_verification_code_successful);
    }

    public static void showCheckVCodeErrorMessage(BaseDataResult<ValidateCodeCheckResponse> responseJson){
        if(responseJson != null && responseJson.getError() != null
                && !TextUtils.isEmpty(responseJson.getError().message)){
            ToastUtil.showToast(responseJson.getError().message);
        }else{
            ToastUtil.showToast(AppContext.getInstance().getString(R.string.code_validate_failed));
        }
    }

    //获取绑定信息
    public static void showCheckBindErrorMessage(BaseDataResult<AccountResponse> ifBindJson){
        if(ifBindJson != null && ifBindJson.getError() != null
                && !TextUtils.isEmpty(ifBindJson.getError().message)){
            ToastUtil.showToast(ifBindJson.getError().message);
        }else{
            ToastUtil.showToast(AppContext.getInstance().getString(R.string.check_if_bound_error));
        }
    }


}
